<template>
  <div class="venus-list-page">
    <!--产品份额查询界面-->
    <div class="page-search">
      <el-row type="flex" class="search-list">
        <el-row type="flex" class="list-items">
          <div class="venus-input-box">
            <label>产品代码/名称</label>
            <el-input
              v-model="table.vol_table.prod_code"
              class="venus-input-middle"
              placeholder="请输入产品代码/名称"
            />
          </div>
          <div class="venus-input-box">
            <label>发生日期区间</label>
            <el-date-picker
              v-model="table.vol_table.start_date"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
            /> -
            <el-date-picker
              v-model="table.vol_table.end_date"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入截止日期"
              value-format="yyyyMMdd"
            />
          </div>
          <div class="venus-input-box">
            <label>审批状态</label>
            <el-select v-model="table.vol_table.check_flag" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
        </el-row>
        <!--      </el-row>-->
        <!--      <el-row type="flex" justify="end">-->

      </el-row>
      <el-row type="flex" class="list-items" justify="space-content">
        <div class="venus-btn-box">
          <el-button type="primary" @click="search">查询</el-button>
        </div>
        <div class="venus-btn-box">
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
        <div class="venus-btn-box">
          <el-button type="primary" @click="addBean">新增</el-button>
        </div>
      </el-row>
    </div>
    <!--    查询列表返显-->
    <div class="page-list">
      <el-row type="flex" justify="space-between" class="page-list-head">
        <div class="title">查询结果</div>
        <el-button type="primary">导出EXCEL</el-button>
      </el-row>
      <table-pagination
        :table-data="table.vol_table.tableData"
        :table-header-config="table.tableHeaderConfig"
        highlight-current-row
        :total="table.vol_table.total"
        :page-size="table.vol_table.pageSize"
        :now-page="table.vol_table.nowPage"
        :operation-config="table.vol_table.operationConfig"
        @current-change="currentChange"
        @table-current-change="sale_get_search"
      />
    </div>
    <div class="page-list">
      <el-row type="flex" justify="space-between" class="page-list-head">
        <div class="title">销售区域信息</div>
      </el-row>
      <el-row type="flex" class="list-items" justify="space-content">
        <div class="venus-input-box">
          <label>销售日期区间</label>
          <el-date-picker
            v-model="table.sale_table.trans_date_min"
            type="date"
            class="venus-input-middle venus-input-date"
            placeholder="请输入起始日期"
            value-format="yyyyMMdd"
          /> -
          <el-date-picker
            v-model="table.sale_table.trans_date_max"
            type="date"
            class="venus-input-middle venus-input-date"
            placeholder="请输入截止日期"
            value-format="yyyyMMdd"
          />
        </div>
        <div class="venus-btn-box">
          <el-button type="primary" @click="sale_search">查询</el-button>
          <el-button type="primary" @click="addSale">新增</el-button>
        </div>
      </el-row>
      <table-pagination
        :table-data="table.sale_table.tableData"
        :table-header-config="table.saleTableHeaderConfig"
        highlight-current-row
        :total="table.sale_table.total"
        :page-size="table.sale_table.pageSize"
        :now-page="table.sale_table.nowPage"
        :operation-config="table.sale_table.operationConfig"
        @current-change="sale_currentChange"
      />
    </div>
    <!--新增弹出框-->
    <el-dialog :title="dlgTilte" :visible.sync="dlgFormVisible">
      <!-- ref=dlgForm用于验证表单 -->
      <el-form ref="dlgForm" :model="dlgForm" size="mini">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品名称"
              :label-width="dlgFormLabelWidth"
              prop="t8_prod_info_id"
              :rules="dlgFormRules.t8_prod_info_id"
            >
              <el-select
                v-model="dlgForm.t8_prod_info_id"
                placeholder="请选择产品名称"
                :disabled="dlgFormDisabled"
                filterable
                clearable
                @change="prod_change"
              >
                <el-option
                  v-for="(value) in dict.t8_prod_info_id"
                  :key="value.id"
                  :label="value.prod_code + '-' + value.prod_name"
                  :value="value.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="0" :sm="0" :md="0">
              <el-input v-model="dlgForm.t8_sys_portfol_id" :disabled="true" type="hidden" />
              <el-input v-model="dlgForm.prod_code" :disabled="true" type="hidden" />
              <el-input v-model="dlgForm.prod_name" :disabled="true" type="hidden" />
              <el-input v-model="dlgForm.open_end_date" :disabled="true" type="hidden" />
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="this.isSeed">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="子产品名称"
              :label-width="dlgFormLabelWidth"
              prop="t8_prod_info_id"
              :rules="dlgFormRules.t8_prod_seed_id"
            >
              <el-select
                v-model="dlgForm.t8_prod_seed_id"
                placeholder="请选择子产品名称"
                :disabled="dlgFormDisabled"
                filterable
                clearable
                @change="sun_prod_change"
              >
                <el-option
                  v-for="(value) in dict.t8_prod_seed_id"
                  :key="value.id"
                  :label="value.prod_code + '-' + value.prod_name"
                  :value="value.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="日期"
              :label-width="dlgFormLabelWidth"
              prop="deal_date"
              :rules="dlgFormRules.deal_date"
            >
              <el-date-picker
                v-model="dlgForm.deal_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd"
                :disabled="deal_date_disable"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="核算方式"
              :label-width="dlgFormLabelWidth"
              prop="acct_mod"
              :rules="dlgFormRules.acct_mod"
            >
              <el-select
                v-model="dlgForm.acct_mod"
                placeholder="请选择核算方式"
                filterable
                clearable
                :disabled="allDisable"
              >
                <el-option
                  v-for="(value,key,index) in dict.t8_busi_account_type"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="收益类型"
              :label-width="dlgFormLabelWidth"
              prop="is_subscetion"
              :rules="dlgFormRules.is_subscetion"
            >
              <el-select
                v-model="dlgForm.is_subscetion"
                placeholder="请选择收益类型"
                :disabled="prodvolA001"
                @change="isSubscetionChange"
              >
                <el-option
                  v-for="(value,key,index) in dict.t8_subscetion"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="prodvolA001_show1">
            <el-form-item
              label="单位净值"
              :label-width="dlgFormLabelWidth"
              prop="unitnet"
              :rules="dlgFormRules.unitnet"
            >
              <el-input v-model="dlgForm.unitnet" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="认购金额(元)"
              :label-width="dlgFormLabelWidth"
              prop="subs_amt"
              :rules="dlgFormRules.subs_amt"
            >
              <el-input v-model="dlgForm.subs_amt" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="认购份额(份)"
              :label-width="dlgFormLabelWidth"
              prop="subs_vol"
              :rules="dlgFormRules.subs_vol"
            >
              <el-input v-model="dlgForm.subs_vol" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="认购手续费"
              :label-width="dlgFormLabelWidth"
              prop="subs_fee"
              :rules="dlgFormRules.subs_fee"
            >
              <el-input v-model="dlgForm.subs_fee" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="赎回份额(份)"
              :label-width="dlgFormLabelWidth"
              prop="redeem_vol"
              :rules="dlgFormRules.redeem_vol"
            >
              <el-input v-model="dlgForm.redeem_vol" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="赎回金额"
              :label-width="dlgFormLabelWidth"
              prop="redeem_amt"
              :rules="dlgFormRules.redeem_amt"
            >
              <el-input v-model="dlgForm.redeem_amt" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="赎回手续费"
              :label-width="dlgFormLabelWidth"
              prop="redeem_fee"
              :rules="dlgFormRules.redeem_fee"
            >
              <el-input v-model="dlgForm.redeem_fee" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="赎回收益"
              :label-width="dlgFormLabelWidth"
              prop="convert_income"
              :rules="dlgFormRules.convert_income"
            >
              <el-input v-model="dlgForm.convert_income" :disabled="allDisable"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="红利再投金额(元)"
              :label-width="dlgFormLabelWidth"
              prop="dividendreinvestment_mon"
              :rules="dlgFormRules.dividendreinvestment_mon"
            >
              <el-input v-model="dlgForm.dividendreinvestment_mon" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="prodvolA001_show">
            <el-form-item
              label="红利再投份额(份)"
              :label-width="dlgFormLabelWidth"
              prop="dividendreinvestment_vol"
              :rules="dlgFormRules.dividendreinvestment_vol"
            >
              <el-input v-model="dlgForm.dividendreinvestment_vol" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="prodvolA001_show">
            <el-form-item
              label="超额业绩报酬"
              :label-width="dlgFormLabelWidth"
              prop="performancereward"
              :rules="dlgFormRules.performancereward"
            >
              <el-input v-model="dlgForm.performancereward" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="红利再投总额(元)"
              :label-width="dlgFormLabelWidth"
              prop="hlzt_amt"
              :rules="dlgFormRules.hlzt_amt"
            >
              <el-input v-model="dlgForm.hlzt_amt" :disabled="allDisable"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="红利再投确认份额(份)"
              :label-width="dlgFormLabelWidth"
              prop="hlzt_vol"
              :rules="dlgFormRules.hlzt_vol"
            >
              <el-input
                v-model="dlgForm.hlzt_vol"
                :disabled="allDisable"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="是否其它机构代销"
              :label-width="dlgFormLabelWidth"
              prop="sale_by_proxy"
              :rules="dlgFormRules.sale_by_proxy"
            >
              <el-select
                v-model="dlgForm.sale_by_proxy"
                :disabled="allDisable"
                @change="isSubscetionChange"
              >
                <el-option
                  v-for="(value,key,index) in dict.sale_by_proxy_dict"
                  :key="index"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="备注"
              :label-width="dlgFormLabelWidth"
              prop="remark"
            >
              <el-input v-model="dlgForm.remark" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="this.prodVolSubDiv">
            <el-form-item
              label="收益率:"
              :label-width="dlgFormLabelWidth"
              prop="yield0"
              :rules="dlgFormRules.yield0"
            >
              <el-input v-model="dlgForm.yield0" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="this.prodVolSubDiv">
            <el-form-item
              label="募集份额(份):"
              :label-width="dlgFormLabelWidth"
              prop="amount_raised0"
              :rules="dlgFormRules.amount_raised0"
            >
              <el-input v-model="dlgForm.amount_raised0" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="this.prodVolSubDiv">
            <el-form-item
              label="募集金额(元):"
              :label-width="dlgFormLabelWidth"
              prop="share_raised0"
              :rules="dlgFormRules.share_raised0"
            >
              <el-input v-model="dlgForm.share_raised0" :disabled="allDisable" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" v-show="this.proxy_sum_money_show">
            <el-form-item
              label="募集金额(元):"
              :label-width="dlgFormLabelWidth"
              prop="proxy_sum_money"
              :rules="dlgFormRules.proxy_sum_money"
            >
              <el-input v-model="dlgForm.proxy_sum_money" :disabled="allDisable" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div v-show="!dlgFormDisabled" slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="success" @click="addOk">确 定</el-button>
        <el-button type="info" plain @click="dlgFormVisible=false">取 消</el-button>
      </div>
    </el-dialog>

    <!--新增销售区域弹出框-->
    <el-dialog :title="saleDlgTilte" :visible.sync="saleDlgFormVisible">
      <!-- ref=dlgForm用于验证表单 -->
      <el-form ref="saleDlgTilte" :model="saleDlgForm" size="mini">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品代码"
              :label-width="dlgFormLabelWidth"
              prop="prod_code"
            >
              <el-input v-model="saleDlgForm.prod_code" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <!-- prop,:rules必须一起写 -->
            <el-form-item
              label="产品名称"
              :label-width="dlgFormLabelWidth"
              prop="prod_name"
            >
              <el-input v-model="saleDlgForm.prod_name" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="0" :sm="0" :md="0">
            <el-input v-model="saleDlgForm.id" :disabled="true" type="hidden" />
            <el-input v-model="saleDlgForm.t8_prod_info_id" :disabled="true" type="hidden" />
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="销售区域"
              :label-width="dlgFormLabelWidth"
              prop="sales_area"
            >
              <el-select
                v-model="saleDlgForm.sales_area"
                placeholder="请选择销售区域"
                :disabled="dlgFormDisabled"
                @change="salesAreaChange"
              >
                <el-option
                  v-for="(value) in dict.trustee_country_data"
                  :key="value.value"
                  :label="value.value + '-' + value.text"
                  :value="value.text"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="销售日期"
              :label-width="dlgFormLabelWidth"
              prop="trans_date"
            >
              <el-date-picker
                v-model="saleDlgForm.trans_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="最近开放起始日"
              :label-width="dlgFormLabelWidth"
              prop="open_start_date"
            >
              <el-date-picker
                v-model="saleDlgForm.open_start_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="最近开放结束日"
              :label-width="dlgFormLabelWidth"
              prop="open_end_date"
            >
              <el-date-picker
                v-model="saleDlgForm.open_end_date"
                type="date"
                class="venus-input-middle venus-input-date"
                placeholder="请输入日期"
                value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="销售份额(份)"
              :label-width="dlgFormLabelWidth"
              prop="subs_vol"
            >
              <el-input v-model="saleDlgForm.subs_vol" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="销售金额"
              :label-width="dlgFormLabelWidth"
              prop="subs_amt"
            >
              <el-input v-model="saleDlgForm.subs_amt" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="个人投资者总数"
              :label-width="dlgFormLabelWidth"
              prop="person_num"
            >
              <el-input v-model="saleDlgForm.person_num" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="法人投资者总数"
              :label-width="dlgFormLabelWidth"
              prop="entity_num"
            >
              <el-input v-model="saleDlgForm.entity_num" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="非法人投资者总数"
              :label-width="dlgFormLabelWidth"
              prop="nonentity_num"
            >
              <el-input v-model="saleDlgForm.nonentity_num" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="认购币种"
              :label-width="dlgFormLabelWidth"
              prop="buy_ccy"
            >
              <el-select
                v-model="saleDlgForm.buy_ccy"
                :disabled="dlgFormDisabled"
              >
                <el-option
                  v-for="(text,key) in dict.t8_currtype_assets"
                  :key="key"
                  :label="text"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div v-show="!dlgFormDisabled" slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="success" @click="okHandler">确 定</el-button>
        <el-button type="info" plain @click="saleDlgFormVisible=false">取 消</el-button>
      </div>
      <div v-show="dlgFormDisabled" slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="info" plain @click="saleDlgFormVisible=false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as kk from '../../../../../utils/k-utils'
  import request from '../../../../../utils/request'
  export default {
    name: 'ProdVol',
    data() { // 数据定义
      return {
        /* 字典 */
        dict: {
          // 数据字典获取
          t8_subscetion: {}, // 收益类型
          sale_by_proxy_dict: {}, // 是否其它机构代销
          t8_currtype_assets: {}, // 认购币种
          t8_busi_account_type: {}, // 核算方式
          // exeid获取
          t8_prod_info_id: [],
          trustee_country_data: [], // 销售区域
          t8_prod_seed_id: [] // 子产品
        },
        // 表格
        table: {
          tableHeaderConfig: [ // 产品份额份额表头配置
            { prop: 'prod_code', label: '产品代码' },
            { prop: 'prod_name', label: '产品名称' },
            { prop: 'deal_date', label: '发生日期' },
            { prop: 'subs_vol', label: '认申购份额(份)' },
            { prop: 'subs_amt', label: '认申购金额' },
            { prop: 'subs_fee', label: '认申购手续费' },
            { prop: 'redeem_vol', label: '赎回份额(份)' },
            { prop: 'redeem_amt', label: '赎回金额' },
            { prop: 'redeem_fee', label: '赎回手续费' },
            { prop: 'convert_income', label: '赎回收益' },
            { prop: 'performancereward', label: '超额业绩报酬' },
            { prop: 'checkflagstr', label: '审批状态' },
            { prop: 'inputuser', label: '操作员' }
          ],
          vol_table: { // 份额表
            limit: 5, // 分页配置
            total: 0, // 数据总条数
            nowPage: 1, // 当前页
            tableData: [], // 表格数据
            exeid: 'pordvolES_002', // exeid
            // 以下是查询参数
            prod_code: '',
            check_flag: '',
            start_date: '',
            end_date: '',
            operationConfig: { // 表格操作配置
              fixed: 'left',
              width: 200,
              operationButton: [
                // value:操作文字； func:回调函数
                { value: '审核', func: this.prodvolreviewed },
                { value: '修改', func: this.prodvolDisable },
                { value: '撤销', func: this.prodVolrevoke },
                { value: '详情', func: this.prodVolDetailHander }
              ]
            }
          },
          saleTableHeaderConfig: [ // 销售区域表头配置
            { prop: 'prod_code', label: '产品代码' },
            { prop: 'prod_name', label: '产品名称' },
            { prop: 'sales_area', label: '销售区域' },
            { prop: 'trans_date', label: '销售日期' },
            { prop: 'open_start_date', label: '最近开放起始日' },
            { prop: 'open_end_date', label: '最近开放结束日' },
            { prop: 'subs_vol', label: '销售份额(份)' },
            { prop: 'subs_amt', label: '销售金额' },
            { prop: 'buy_ccy', label: '认购币种' },
            { prop: 'person_num', label: '个人投资者总数' },
            { prop: 'entity_num', label: '法人投资者总数' },
            { prop: 'nonentity_num', label: '非法人投资者总数' },
            { prop: 'inputuser', label: '操作员' }
          ],
          sale_table: { // 销售区域
            limit: 5, // 分页配置
            total: 0, // 数据总条数
            nowPage: 1, // 当前页
            tableData: [], // 销售区域表格数据
            exeid: 'prodSalesES_001', // exeid
            // 以下是查询参数
            t8_prod_info_id: '',
            trans_date_min: '',
            trans_date_max: '',
            operationConfig: { // 表格操作配置
              fixed: 'left',
              width: 200,
              operationButton: [
                // value:操作文字； func:回调函数
                { value: '修改', func: this.prodvolDisable },
                { value: '删除', func: this.prodVolDetailHander }
              ]
            }
          }
        },
        /* ===========新增，修改，详情=============== */
        dlgTilte: '标题',
        saleDlgTilte: '标题',
        dlgFormVisible: false,
        saleDlgFormVisible: false,
        dlgFormLabelWidth: '160px',
        isSeed: false,
        prodVolSubDiv: false,
        prodvolA001: false,
        deal_date_disable: false,
        prodvolA001_show: true,
        prodvolA001_show1: false,
        allDisable: false,
        proxy_sum_money_show: false,
        dlgForm: {
          id: '', // 主键
          t8_prod_info_id: '', // 产品名称
          t8_sys_portfol_id: '', // 产品组合
          prod_code: '', // 产品代码
          prod_name: '', // 产品名称
          t8_prod_seed_id: '', // 子产品名称
          deal_date: '', // 日期
          open_end_date: '', // 开放结束日
          acct_mod: '', // 核算方式
          unitnet: '', // 单位净值
          subs_amt: '', // 认购金额
          subs_vol: '', // 认购份额(份)
          subs_fee: '', // 认购手续费
          redeem_vol: '', // 赎回份额(份)
          redeem_amt: '', // 赎回金额
          redeem_fee: '', // 赎回手续费
          convert_income: '', // 赎回收益
          dividendreinvestment_mon: '', // 红利再投金额(元)
          dividendreinvestment_vol: '', // 红利再投份额(份)
          performancereward: '', // 超额业绩报酬
          hlzt_amt: '', // 红利再投总额(元)
          hlzt_vol: '', // 红利再投确认份额(份)
          sale_by_proxy: '', // 是否其它机构代销
          remark: '', // 备注
          proxy_sum_money: '', // 代销总额
          t8_org_trustee_info_id: '', // 托管行ID
          yield0: '', // 收益率
          amount_raised0: '', // 募集份额(份)
          share_raised0: '', // 募集金额(元)
          is_subscetion: '' // 收益类型
        },
        dlgFormRules: {
          t8_prod_info_id: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          deal_date: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          acct_mod: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          subs_amt: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          subs_vol: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          subs_fee: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          redeem_vol: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          redeem_amt: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          redeem_fee: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          convert_income: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          dividendreinvestment_mon: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          dividendreinvestment_vol: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          performancereward: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          hlzt_amt: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          hlzt_vol: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          sale_by_proxy: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          yield0: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          amount_raised0: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          share_raised0: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          is_subscetion: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ],
          proxy_sum_money: [
            { required: true, message: '该项不能为空', trigger: 'change' }
          ]
        },
        saleDlgForm: {
          id: '', // 主键
          t8_prod_info_id: '', // 产品名称
          t8_sys_portfol_id: '', // 产品组合
          prod_code: '', // 产品代码
          prod_name: '', // 产品名称
          sales_area: '', // 销售区域
          trans_date: '', // 销售日期
          open_start_date: '', // 最近开放起始日
          open_end_date: '', // 最近开放结束日
          subs_amt: '', // 销售金额
          subs_vol: '', // 销售份额(份)
          person_num: '', // 个人投资者总数
          entity_num: '', // 法人投资者总数
          nonentity_num: '', // 非法人投资者总数
          buy_ccy: '' // 认购币种
        },
        dlgFormDisabled: false, // 是否禁用，新增、修改不禁用，详情禁用
        options: [{
          value: '0',
          label: '未审批'
        }, {
          value: '1',
          label: '已审批'
        }]
      }
    },
    mounted() {
      // 初始化调用
      this.init()
    },
    methods: {
      init: function() {
        kk.k_load_dict(this, 't8_subscetion', 't8_subscetion')
        kk.k_load_dict(this, 'sale_by_proxy_dict', 't8_1yes0no')
        kk.k_load_dict(this, 't8_currtype_assets', 't8_currtype_assets')
        kk.k_load_dict(this, 't8_busi_account_type', 't8_busi_account_type')
        kk.k_load_dict(this, 'sales_area_dict', 'sales_area_dict')
        this.load_dict_exeid(this, 'prod', 'pordvolEC_001', 't8_prod_info_id')
        this.load_dict_exeid(this, 'prod', 'prodSalesES_002', 'trustee_country_data')
        /* 加载表格数据 */
        this.table.vol_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'vol_table', 'prod')
      },
      /* 通过exeid加载字典 */
      load_dict_exeid(this_object, service_name, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post'
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      },
      search() { // 查询函数
        this.table.vol_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'vol_table', 'prod')
        this.table.sale_table.tableData = '' // 清空销售表数据
      },
      // 下一页触发的事件
      currentChange(index) {
        this.table.vol_table.nowPage = index
        kk.k_load_table(this, 'vol_table', 'prod')
      },
      sale_get_search(params) { // 查询函数
        this.table.sale_table.nowPage = 1 // 初始第一页
        this.table.sale_table.t8_prod_info_id = params.t8_prod_info_id // 查询该产品的销售区域字段
        this.saleDlgForm.prod_code = params.prod_code // 新增代销区域产品代码字段
        this.saleDlgForm.prod_name = params.prod_name // 新增代销区域产品名称字段
        kk.k_load_table(this, 'sale_table', 'prod')
      },
      sale_search() { // 查询函数
        this.table.sale_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'sale_table', 'prod')
      },
      // 下一页触发的事件
      sale_currentChange(index) {
        this.table.sale_table.nowPage = index
        kk.k_load_table(this, 'sale_table', 'prod')
      },
      reset() { // 重置函数
        this.table.vol_table.prod_code = ''
        this.table.vol_table.check_flag = ''
        this.table.vol_table.start_date = ''
        this.table.vol_table.end_date = ''
      },
      addBean() {
        this.dlgTilte = '新增产品份额信息'
        this.dlgFormDisabled = false // 是否禁用输入框
        this.dlgOkHandler = 'addOk' // 自己定义调用那个函数
        // 清空数据
        this.copyObj({
          id: '', // 主键
          t8_prod_info_id: '', // 产品名称
          t8_sys_portfol_id: '', // 产品组合
          prod_code: '', // 产品代码
          prod_name: '', // 产品名称
          t8_prod_seed_id: '', // 子产品名称
          deal_date: '', // 日期
          open_end_date: '', // 开放结束日
          acct_mod: '', // 核算方式
          unitnet: '', // 单位净值
          subs_amt: '', // 认购金额
          subs_vol: '', // 认购份额(份)
          subs_fee: '', // 认购手续费
          redeem_vol: '', // 赎回份额(份)
          redeem_amt: '', // 赎回金额
          redeem_fee: '', // 赎回手续费
          convert_income: '', // 赎回收益
          dividendreinvestment_mon: '', // 红利再投金额(元)
          dividendreinvestment_vol: '', // 红利再投份额(份)
          performancereward: '', // 超额业绩报酬
          hlzt_amt: '', // 红利再投总额(元)
          hlzt_vol: '', // 红利再投确认份额(份)
          sale_by_proxy: '', // 是否其它机构代销
          remark: '', // 备注
          proxy_sum_money: '', // 代销总额
          t8_org_trustee_info_id: '' // 托管行ID
        }, this.dlgForm)
        this.$nextTick(() => {
          // this.$refs.dlgForm.resetField() // 这个在第一次点击新增的时候报错，点击修改在点击新增就不报错
          // 点击修改在点击新增，去掉校验提示
          this.$refs.dlgForm.clearValidate() // 必须写在$nextTick里面
        })
        // 隐藏个别属性
        this.dlgFormVisible = true
      },
      addSale() {
        this.saleDlgTilte = '新增销售区域'
        this.dlgFormDisabled = false // 是否禁用输入框
        this.saleDlgOkHandler = 'addSaleOk' // 自己定义调用那个函数
        // 清空数据
        this.copyObj({
          sales_area: '', // 销售区域
          trans_date: '', // 销售日期
          open_start_date: '', // 最近开放起始日
          open_end_date: '', // 最近开放结束日
          subs_vol: '', // 销售份额(份)
          subs_amt: '', // 销售金额
          person_num: '', // 个人投资者总数
          entity_num: '', // 法人投资者总数
          nonentity_num: '', // 非法人投资者总数
          buy_ccy: '' // 认购币种
        }, this.saleDlgForm)
        this.$nextTick(() => {
          // this.$refs.dlgForm.resetField() // 这个在第一次点击新增的时候报错，点击修改在点击新增就不报错
          // 点击修改在点击新增，去掉校验提示
          this.$refs.saleDlgForm.clearValidate() // 必须写在$nextTick里面
        })
        // 隐藏个别属性
        this.dlgFormVisible = false
        this.saleDlgFormVisible = true
      },
      /*
       * 将obj1对象的数据拷贝到obj对象
       */
      copyObj(obj1, obj2) {
        for (var key in obj1) {
          if (key === '__proto__') {
            continue
          }
          obj2[key] = obj1[key]
        }
      },
      addOk() {
        this.$refs.dlgForm.validate((valid) => {
          if (valid) {
            var param = this.dlgForm
            this.formatDataToBack(param)
            if (param.t8_prod_seed_id) {
              param.t8_prod_info_id = param.t8_prod_seed_id
            }
            if (param.redeem_vol == "undefined" || param.redeem_vol == '') {
              param.redeem_vol = 0 // 赎回份额 不填写会影响产品的实际规模
              param.redeem_amt = 0 // 赎回金额 不填写会影响产品的实际规模
            }
            var close = false
            request({
              loading: true,
              url: 'prod/addProdVol.json',
              method: 'post',
              params: param
            }).then(rep => {
              if(rep.success) {
                alert("添加成功")
                close = true
                this.$refs.dlgForm.resetFields()
                this.isSubscetionChange('0')
              }
            })
            return close
          } else {
            console.log('表单数据检验没有全部通过！！')
          }
        })
      },
      formatDataToBack(param) { // 向后台提交前，格式化分段收益参数
        if (!param || param.is_subscetion != 1) {
          return param
        }
        var names = ['yield', 'amount_raised', 'share_raised']
        $.each(names, function(i, key) {
          param[key] = new Array()
        })
        var index = 0
        while (true) {
          $.each(names, function(i, key) {
            if (!isEmpty(param[key + index])) {
              param[key].push(param[key + index])
            }
          })
          index++
          // index最大不超过100
          if (isEmpty(param['yield' + index]) || index > 100) {
            break
          }
        }
        return param
      },
      addSaleOk() {
        var _this = this
        this.$refs.saleDlgForm.validate((valid) => {
          if (valid) {

          } else {
            console.log('表单数据检验没有全部通过！！')
          }
        })
      },
      prodvolreviewed() { // 审核函数

      },
      prodvolDisable(params) { // 份额修改函数
        this.dlgTilte = '产品份额修改'
        this.dlgFormDisabled = false // 是否禁用输入框
        this.dlgOkHandler = 'addOk' // 自己定义调用那个函数
        // 赋值
        this.copyObj(params, this.dlgForm)
        // 隐藏个别属性
        this.dlgFormVisible = true
        this.$nextTick(() => {
          // this.$refs.dlgForm.resetField() // 这个在第一次点击新增的时候报错，点击修改在点击新增就不报错
          // 点击修改在点击新增，去掉校验提示
          this.$refs.dlgForm.clearValidate() // 必须写在$nextTick里面
        })
      },
      prodVolrevoke() { // 撤销函数

      },
      prodVolDetailHander(params) { // 详情函数
        this.dlgTilte = '产品份额详情'
        this.dlgFormDisabled = true // 是否禁用输入框
        this.allDisable = true
        this.saleProxyChange(params.sale_by_proxy)
        this.prodVolPopInitByAcct_Mod(params.acct_mod)
        // 赋值
        this.copyObj(params, this.dlgForm)
        this.dlgFormVisible = true
        this.$nextTick(() => {
          // this.$refs.dlgForm.resetField() // 这个在第一次点击新增的时候报错，点击修改在点击新增就不报错
          // 点击修改在点击新增，去掉校验提示
          this.$refs.dlgForm.clearValidate() // 必须写在$nextTick里面
        })
      },
      prodVolPopInitByAcct_Mod(acct_mod) {
        if (acct_mod && acct_mod == 2) { // 净值型
          this.prodvolA001_show1 = true
          this.prodvolA001_show = true
        } else {
          this.prodvolA001_show1 = false
          this.prodvolA001_show = false
        }
      },
      saleProxyChange(param) {
        if (1 == param) {
          this.proxy_sum_money_show = true
        } else {
          this.proxy_sum_money_show = false
        }
      },
      prod_change(params) { // 产品变更
        this.prodInfoChange(params)
        if (params.father_type == 1) {
          this.isSeed = true
          this.load_dict_exeid_byParams(this, 'prod', { superior_prod_info_id: params.id }, 'pordvolEC_0011', 't8_prod_seed_id')
        } else {
          this.isSeed = false
          this.dlgForm.t8_prod_seed_id = ''
        }
      },
      sun_prod_change(params) { // 子产品变更
        this.prodInfoChange(params)
      },
      prodInfoChange(params) { // 产品信息联动
        if (params.establish_date) {
          // 日期
          this.dlgForm.deal_date = params.establish_date
        }
        if (params.acct_mod) {
          // 核算方式
          this.dlgForm.acct_mod = params.acct_mod
        }
        if (params.prod_mod && (params.prod_mod == 2 || params.prod_mod == 5)) {
          // 封闭式产品
          this.deal_date_disable = true
        } else {
          this.deal_date_disable = false
        }
        if (params.acct_mod && params.acct_mod == 2) { // 净值型
          this.prodvolA001 = true
          this.dlgForm.is_subscetion = 0
          this.isSubscetionChange('0')
          this.prodvolA001_show1 = true
          this.prodvolA001_show = true
        } else {
          this.prodvolA001_show1 = false
          this.prodvolA001_show = false
          this.prodvolA001 = false
        }
        this.dlgForm.t8_sys_portfol_id = params.t8_sys_portfol_id
        this.dlgForm.prod_code = params.prod_code
        this.dlgForm.prod_name = params.prod_name
      },
      isSubscetionChange(param) { // 收益类型变更
        if (param && param == 1) {
          this.prodVolSubDiv = true
        } else {
          this.prodVolSubDiv = false
        }
      },
      salesAreaChange(param) {
        // 净值型产品
        if (this.dlgForm.prod_mod == 2 || this.dlgForm.prod_mod == 5) {
          if (param == "210000") {//辽宁省
            alert('该省的销售份额(份)和销售金额(元)请填写除大连市以外的汇总数据');
          }
          if (param == "330000") {//浙江省
            alert('该省的销售份额(份)和销售金额(元)请填写除宁波市以外的汇总数据');
          }
          if (param == "370000") {//山东省
            alert('该省的销售份额(份)和销售金额(元)请填写除青岛市以外的汇总数据');
          }
          if (param == "440000") {//广东省
            alert('该省的销售份额(份)和销售金额(元)请填写除深圳市以外的汇总数据');
          }
        }
      },
      /* 通过exeid加载字典 */
      load_dict_exeid_byParams(this_object, service_name, params, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post',
          params: params
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      }
    }
  }
</script>

<style scoped>
</style>
